/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jschoolmanagerportable.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "COLEGIOS")
@NamedQueries({@NamedQuery(name = "Colegio.findById", query = "SELECT c FROM Colegio c WHERE c.id = :id"), @NamedQuery(name = "Colegio.findByNombre", query = "SELECT c FROM Colegio c WHERE c.nombre = :nombre"), @NamedQuery(name = "Colegio.findByDescripcion", query = "SELECT c FROM Colegio c WHERE c.descripcion = :descripcion"), @NamedQuery(name = "Colegio.findByPeriodos", query = "SELECT c FROM Colegio c WHERE c.periodos = :periodos")})
public class Colegio implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy=GenerationType.TABLE, generator="colegios")
    @TableGenerator(name="colegios", table="sequencer", pkColumnName="class_name",valueColumnName="class_id")    
    private Integer id;
    @Column(name = "NOMBRE", nullable = false)
    private String nombre;
    @Column(name = "DESCRIPCION", nullable = false)
    private String descripcion;
    @Column(name = "PERIODOS", nullable = false)
    private int periodos;
    @OneToMany(cascade=CascadeType.ALL, mappedBy = "idcolegio")
    private Collection<Curso> cursoCollection;

    public Colegio() {
    }

    public Colegio(Integer id) {
        this.id = id;
    }

    public Colegio(Integer id, String nombre, String descripcion, int periodos) {
        this.id = id;
        this.nombre = nombre;
        this.descripcion = descripcion;
        this.periodos = periodos;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        String oldNombre = this.nombre;
        this.nombre = nombre;
        changeSupport.firePropertyChange("nombre", oldNombre, nombre);
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        String oldDescripcion = this.descripcion;
        this.descripcion = descripcion;
        changeSupport.firePropertyChange("descripcion", oldDescripcion, descripcion);
    }

    public int getPeriodos() {
        return periodos;
    }

    public void setPeriodos(int periodos) {
        int oldPeriodos = this.periodos;
        this.periodos = periodos;
        changeSupport.firePropertyChange("periodos", oldPeriodos, periodos);
    }

    public Collection<Curso> getCursoCollection() {
        return cursoCollection;
    }

    public void setCursoCollection(Collection<Curso> cursoCollection) {
        this.cursoCollection = cursoCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Colegio)) {
            return false;
        }
        Colegio other = (Colegio) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.getNombre();
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

}
